package com.bangdream.michelia.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bangdream.michelia.R;
import com.bangdream.michelia.tool.glide.GlideCircleTransform;
import com.bangdream.michelia.tool.glide.GlideRoundTransform;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;

/**
 * 图片加载
 */
public class ImageLoadUtils {
    private static final String TAG = "ImageLoadUtlis";
    public static void ImageLoad(Context context, String url, ImageView imageView,int placeholder) {
        if(url==null||url.length()==0){
            url = "1";
        }
        GlideUrl glideUrl = new GlideUrl(url
                , new LazyHeaders.Builder().addHeader("Cookie", "AppCurrentUser.getInstance().getUserCookie()").build());
        Glide.with(context).load(glideUrl)
                //设置不使用内存缓存中查找也不存储内存缓存
                //.config(Bitmap.Config.RGB_565)
                //.centerCrop()
                .placeholder(placeholder)      //说明：当图片没有加载上的时候，显示的图片
                .error(R.mipmap.img_load_failed)     // 说明：当图片加载错误的时候，显示图片
                //.transform(getTransformation(imageView))
                .into(imageView);


    }
    //加载圆角图片
    public static void loadRoundCornerImage(Context context, String url, ImageView imageView) {
        if(url==null||url.length()==0){
            url = "1";
        }
        GlideUrl glideUrl = new GlideUrl(url
                , new LazyHeaders.Builder().addHeader("Cookie", "AppCurrentUser.getInstance().getUserCookie()").build());
        Glide.with(context)
                .load(glideUrl)
                .transform(new CenterCrop(context), new GlideRoundTransform(context))
                //.placeholder(placeholder)
                //.error(placeholder)
                //.diskCacheStrategy(DiskCacheStrategy.ALL)
                //.crossFade()
                .into(imageView);
    }
    //加载圆角图片
    public static void loadRoundCornerImage(Context context, String url, ImageView imageView,int placeholder,int error) {
        if(url==null||url.length()==0){
            url = "1";
        }
        GlideUrl glideUrl = new GlideUrl(url
                , new LazyHeaders.Builder().addHeader("Cookie", "AppCurrentUser.getInstance().getUserCookie()").build());
        Glide.with(context)
                .load(glideUrl)
                .transform(new CenterCrop(context), new GlideRoundTransform(context))
                //.placeholder(placeholder)
                //.error(placeholder)
                //.diskCacheStrategy(DiskCacheStrategy.ALL)
                //.crossFade()
                .into(imageView);
    }
}
